<template>
	<view class="wrap">
		<div class="turtle_mes">
			<div class="inp_box">
				<uni-easyinput class="form_inp" v-model="formData.title" focus placeholder="输入记录名称（换水/喂食）"/>
			</div>
			<div class="inp_box">
				<uni-easyinput class="form_inp" v-model="formData.text_container" placeholder="输入记录内容（龟尺寸/产蛋记录）"/>
			</div>
		</div>

		

		<div class="add_turtle" @click="addRecord">提交</div>
	</view>
</template>

<script>
import { dateTimeStr } from '../../common/public';
	export default {
		components: {
			
		},
		data() {
			return {
				theId: "",
                formData: {
                    title: "",
					text_container: "",
                },
				nowTime: '',
			}
		},
		
		methods: {
			addRecord() {
				if ( this.formData.title && this.formData.text_container ) {
					uniCloud.callFunction({
						name: 'addRecordList',
						data: {
							turtle_id: this.theId,
        					record: {
								time: this.nowTime,
								title: this.formData.title,
								text_container: this.formData.text_container,
							}
						},
						success(res) {
							uni.showToast({
								duration: 2000,
								icon: "success",
								title: "提交成功",
							});
							setTimeout(() => {
								uni.navigateBack()
							}, 2000);
						},
						fail(e) {
							console.log(e);
						}
					})
				} else {
					uni.showToast({
					   duration:3000,
				       icon: "none",
				       title: "请补充完整信息后提交",
				    });
				}
				
			}
		},
		onLoad(option) {
			this.theId = option.id;
			var timeStr = dateTimeStr('y-m-d'); // y:年 m:月 d:日 h:时 i:分 s:秒 中间的分割符号可更改
			this.nowTime = timeStr;
			console.log('timeStr',timeStr)
		}
	}
</script>

<style lang="scss" scoped>
.wrap{
	width: 100%;
	min-height: 100vh;
	overflow-x: hidden;
    padding: 20rpx;
	.turtle_mes {
		width: 100%;
		padding: 20px;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		.inp_box {
			margin-bottom: 30rpx;
		}
	}
	.add_turtle {
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		background: #3d836d;
		color: #fff;
		border-radius: 20rpx;
		font-size: 32rpx;
	}

}
</style>
